//计算一个数组中小数的和
const fn = (arr: Array<number>)=>{
    return process(arr,0,arr.length-1)
}
const process = (arr: Array<number>,L:number,R:number):number => {
    if(L == R) return 0
    let mid = L + ((R-L) >>1)
    console.log(process(arr,L,mid),'r')
    process(arr,mid+1,R)
    return merge(arr,L,mid,R)
}

const merge = (arr:Array<number>,L:number,M:number,R:number):number =>{
    console.log(arr)
    let help:Array<number> = []
    let i = 0
    let p1 = L
    let p2 = M+1
    let num = 0
    while (p1 <= M && p2 <= R){
        console.log( arr[p1] < arr[p2],num,arr[p1]*(R-p2+1))
        num += arr[p1] < arr[p2] ? arr[p1]*(R-p2+1) : 0
        help[i++] = arr[p1] < arr[p2] ? arr[p1++] : arr[p2++] 
    }
    while(p1 <= M){
        help[i++] = arr[p1++]
    }
    while(p2 <= R){
        help[i++] = arr[p2++]
    }
    for(i = 0; i < help.length; i++){
        arr[L+i] = help[i]
    }
    console.log(typeof num,num)
    return num
}
console.log(fn([1,3,4,2,5]))
export default process